{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ollama_ocr import OCRProcessor\n",
    "\n",
    "# Create an instance\n",
    "ocr = OCRProcessor(model_name='llama3.2-vision:11b')\n",
    "\n",
    "# Test with an image (replace with your image path)\n",
    "result = ocr.process_image(\n",
    "    image_path=\"input\\img.png\",\n",
    "    format_type=\"markdown\"\n",
    ")\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing images:   0%|          | 0/2 [00:00<?, ?it/s]"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing images: 100%|██████████| 2/2 [56:54<00:00, 1707.14s/it]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'total': 2, 'successful': 2, 'failed': 0}\n"
     ]
    }
   ],
   "source": [
    "# Test batch processing\n",
    "batch_results = ocr.process_batch('input')\n",
    "print(batch_results['statistics'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Processing Statistics:\n",
      "Total images: 2\n",
      "Successfully processed: 2\n",
      "Failed: 0\n"
     ]
    }
   ],
   "source": [
    "# Print statistics\n",
    "print(\"\\nProcessing Statistics:\")\n",
    "print(f\"Total images: {batch_results['statistics']['total']}\")\n",
    "print(f\"Successfully processed: {batch_results['statistics']['successful']}\")\n",
    "print(f\"Failed: {batch_results['statistics']['failed']}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "File: input\\img.png\n",
      "--------------------------------------------------\n",
      "Extracted Text: **Invoice #1024**\n",
      "\n",
      "**Billed To:**\n",
      "Really Great Company\n",
      "\n",
      "**Pay To:**\n",
      "Avery Davis\n",
      "123 Anywhere St., Any City\n",
      "123-456-7890\n",
      "\n",
      "**Bank Information:**\n",
      "Really Great Bank\n",
      "Account Name: John Smith\n",
      "BSB: 000-000\n",
      "Account Number: 0000 0000\n",
      "\n",
      "**Description of Services:**\n",
      "\n",
      "*   **Content Plan:** $200.00\n",
      "*   **Copy Writing:** $100.00\n",
      "*   **Website Design:** $250.00\n",
      "*   **Website Development:** $500.00\n",
      "*   **SEO:** $200.00\n",
      "\n",
      "**Sub-Total:** $1,250.00 (30% discount applied)\n",
      "\n",
      "**Total:** $875.00\n",
      "\n",
      "**Payment Terms:**\n",
      "\n",
      "*   Payment is required within 14 business days of invoice date.\n",
      "*   Please send remittance to hello@reallygreatsite.com.\n",
      "\n",
      "**Thank You for Your Business**\n",
      "\n",
      "This invoice outlines the services provided by Really Great Company to Avery Davis, including content planning, copywriting, website design, website development, and SEO. The total amount due is $875.00, with a 30% discount applied to the sub-total of $1,250.00. Payment is required within 14 business days of invoice date, and remittances should be sent to hello@reallygreatsite.com.\n",
      "\n",
      "File: input\\img1.png\n",
      "--------------------------------------------------\n",
      "Extracted Text: **Summary**\n",
      "The image presents a passage of text that appears to be an excerpt from a literary work, possibly a poem or short story. The text is written in a formal, elegant style, with attention paid to sentence structure, word choice, and punctuation.\n",
      "\n",
      "**Text Content**\n",
      "\n",
      "*   **Date**: November 11 (presumably the date on which this passage was written)\n",
      "*   **Author's Name**: Ishmael (implied by the content of the passage, rather than explicitly stated)\n",
      "\n",
      "**Passage Content**\n",
      "The passage begins with a reflective tone, as if the author is reminiscing about past experiences or events. The text describes a person named Ishmael who has had little success in life and is now contemplating his place in the world. The author notes that they have not achieved much in terms of wealth or fame but are content with their current situation.\n",
      "\n",
      "The passage then shifts to a more introspective tone, as if the author is grappling with existential questions about the meaning of life. They express frustration at being unable to find purpose or direction and wonder whether it is possible for anyone to truly know what they want in life.\n",
      "\n",
      "Overall, this passage presents a thought-provoking exploration of themes such as identity, ambition, and self-discovery. Through the use of vivid imagery and philosophical musings, the author invites readers to consider their own values and priorities in light of Ishmael's experiences.\n",
      "\n",
      "**Language Features**\n",
      "The language used throughout the passage is characterized by:\n",
      "\n",
      "*   **Formal tone**: The text employs a formal, polished style that suggests it may be from an older work.\n",
      "*   **Elegant sentence structure**: Sentences are carefully crafted to convey complex ideas and emotions in a clear, concise manner.\n",
      "*   **Poetic language**: The use of metaphors (\"circumference of the skull\") and other literary devices adds depth and richness to the text.\n",
      "\n",
      "**Visual Features**\n",
      "The image itself is a simple scan of black text on a white background. There are no illustrations or graphics to distract from the focus on the written word.\n"
     ]
    }
   ],
   "source": [
    "# Get text from all successfully processed images\n",
    "for file_path, text in batch_results['results'].items():\n",
    "    print(f\"\\nFile: {file_path}\")\n",
    "    print(\"-\" * 50)\n",
    "    print(f\"Extracted Text: {text}\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Check if there were any errors\n",
    "if batch_results['errors']:\n",
    "    print(\"\\nErrors:\")\n",
    "    for file_path, error in batch_results['errors'].items():\n",
    "        print(f\"Error in {file_path}: {error}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ollama_ocr import OCRProcessor\n",
    "\n",
    "# Create an instance\n",
    "ocr = OCRProcessor(model_name='llama3.2-vision:11b')\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Test with key-value format\n",
    "result = ocr.process_image(\n",
    "    image_path=\"input\\img.png\",\n",
    "    format_type=\"key_value\"\n",
    ")\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Text\n",
    "result = ocr.process_image(\n",
    "    image_path=\"input\\img.png\",\n",
    "    format_type=\"text\"\n",
    ")\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  json format\n",
    "result = ocr.process_image(\n",
    "    image_path=\"input\\img.png\",\n",
    "    format_type=\"json\"\n",
    ")\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  structured format\n",
    "result = ocr.process_image(\n",
    "    image_path=\"input\\img.png\",\n",
    "    format_type=\"structured\"\n",
    ")\n",
    "print(result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
